extends CanvasLayer

@onready var color_rect: ColorRect = $ColorRect
@export var fade_duration: float = 0.1
@export var target_pixel_size:float = 0.03


func _ready() -> void:
	var mat = color_rect.material as ShaderMaterial
	mat.set_shader_parameter("pixel_size", 0.002)
	mat.set_shader_parameter("mask_alpha", 0.0)


func fade_in():
	var tween = create_tween()
	tween.tween_property(color_rect.material, "shader_parameter/pixel_size", target_pixel_size, fade_duration).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_IN).from_current()
	
	tween = create_tween()
	tween.tween_property(color_rect.material, "shader_parameter/mask_alpha", 1.0, fade_duration).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_IN).from_current()

func fade_out():
	var tween = create_tween()
	tween.tween_property(color_rect.material, "shader_parameter/pixel_size", 0.002, fade_duration).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT).from_current()
	
	tween = create_tween()
	tween.tween_property(color_rect.material, "shader_parameter/mask_alpha", 0, fade_duration).set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT).from_current()
